using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL {

/// <summary>
/// The TownshipCodeTableManager class is responsible for managing BO.TownshipCodeTable objects in the system.
/// </summary>
[DataObjectAttribute()]
public class TownshipCodeTableManager
  {

#region "Public Methods"

/// <summary>
/// Gets a list with all TownshipCodeTable objects in the database.
/// </summary>
/// <returns>A list with all TownshipCodeTable from the database when the database contains any, or null otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, true)]
public static TownshipCodeTableList GetList(){
return TownshipCodeTableDB.GetList();
}

/// <summary>
/// Gets a single TownshipCodeTable from the database without its data.
/// </summary>
/// <param name="townshipCode">The TownshipCode of the TownshipCodeTable in the database.</param>
/// <returns>A TownshipCodeTable object when the TownshipCode exists in the database, or <see langword="null"/> otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static TownshipCodeTable GetItem(short townshipCode){
return GetItem(townshipCode, false);
}

/// <summary>
/// Gets a single TownshipCodeTable from the database.
/// </summary>
/// <param name="townshipCode">The TownshipCode of the TownshipCodeTable in the database.</param>
/// <param name="getTownshipCodeTableRecords">Determines whether to load all associated TownshipCodeTable records as well.</param>
/// <returns>
/// A TownshipCodeTable object when the TownshipCode exists in the database, or <see langword="null"/> otherwise.
/// </returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static TownshipCodeTable GetItem(short townshipCode, bool getTownshipCodeTableRecords){
TownshipCodeTable myTownshipCodeTable = TownshipCodeTableDB.GetItem(townshipCode);
return myTownshipCodeTable;
}

/// <summary>
/// Saves a TownshipCodeTable in the database.
/// </summary>
/// <param name="myTownshipCodeTable">The TownshipCodeTable instance to save.</param>
/// <returns>The new TownshipCode if the TownshipCodeTable is new in the database or the existing TownshipCode when an item was updated.</returns>
[DataObjectMethod(DataObjectMethodType.Update, true)]
public static short Save(TownshipCodeTable myTownshipCodeTable){
using (TransactionScope myTransactionScope = new TransactionScope()){
short townshipCodeTableTownshipCode = TownshipCodeTableDB.Save(myTownshipCodeTable);

//  Assign the TownshipCodeTable its new (or existing TownshipCode).
myTownshipCodeTable.TownshipCode = townshipCodeTableTownshipCode;

myTransactionScope.Complete();

return townshipCodeTableTownshipCode;
}
}

/// <summary>
/// Deletes a TownshipCodeTable from the database.
/// </summary>
/// <param name="myTownshipCodeTable">The TownshipCodeTable instance to delete.</param>
/// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static bool Delete(TownshipCodeTable myTownshipCodeTable){
return TownshipCodeTableDB.Delete(myTownshipCodeTable.TownshipCode);
}

#endregion

}

}
